package com.flyme.module.base.provider.controller;

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.flyme.common.core.model.ResultBody;
import com.flyme.common.core.model.query.CriteriaQuery;
import com.flyme.common.core.model.query.PagerInfo;
import com.flyme.common.core.model.query.PqGrid;
import com.flyme.core.base.supper.controller.BaseController;
import com.flyme.core.base.supper.entity.EntityMap;
import com.flyme.module.base.client.api.SysExamseasonRemoteService;
import com.flyme.module.base.client.entity.SysExamseason;
import com.flyme.module.base.provider.service.SysExamseasonService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;


/**
 * 考试场次安排管理
 * @author zyh
 * @date 2020-7-22
 */
@Api(tags = "考试场次安排")
@RestController
public class SysExamseasonController extends BaseController<SysExamseasonService, SysExamseason> implements SysExamseasonRemoteService {


    /**
     * 考试安排列表
     */
    @Override
    public ResultBody list(PagerInfo pagerInfo, SysExamseason examseason) {
        CriteriaQuery cq = new CriteriaQuery<EntityMap>(pagerInfo);
        cq.select("*");
        cq.eq("examinationId", examseason.getExaminationId());
        PqGrid pqGrid = bizService.pageList(cq);
        return ResultBody.success(pqGrid);
    }

    /**
     * 获取考试详情
     */
    @ApiOperation(value = "通过id查询")
    @Override
    public ResultBody get(@PathVariable Long id) {
        EntityMap map = new EntityMap();
        SysExamseason examseason = bizService.getById(id);
        map.put("detail", examseason);
        return ResultBody.success().setData(map);
    }

    /**
     * 添加/修改
     */
    @Override
    public ResultBody sessionsEdit(SysExamseason examseason, String examTimeDate) {
        //examseason.setExamTime(DateUtil.parse(examTimeDate));
        Boolean tag = bizService.saveOrUpdate(examseason);
        return ResultBody.success("添加成功").setData(tag);
    }

    /**
     * 更新考试安排状态
     */
    @ApiOperation(value = "更新考试安排状态", notes = "更新考试安排状态")
    @Override
    public ResultBody setSessionsStatus(@RequestParam Long id, @RequestParam Integer status) {
        boolean result = bizService.update(new UpdateWrapper<SysExamseason>().set("status",status).eq("id",id));
        return ResultBody.ok("设置成功").setData(result);
    }

}
